<?php 	
	//计算当天到此时入店的人的平均来访周期
	
	//设置时区
	ini_set('date.timezone','Asia/Shanghai');
    $conn = new mysqli("localhost:3306","root","lc971019");
	if($conn->connect_error)
	{
		die('Could not connect:'.$conn->connect_error());
	}
	
	//从上午8点开始计算
	$time_start = date("Y-m-d",intval(time()))." 08:00:00";
	//现在的时间
	$time_end = date("Y-m-d H:i:s",intval(time()));
	$sum=0;
	$sql="select wifidata.mac, min(wifidata.times), ltc.times from wifidata,ltc where wifidata.mac = ltc.mac and ranges < 200 group by wifidata.mac;";
	$result_VC = $conn->query($sql);
	$i=0;
	if($result_VC->num_rows > 0){
		while($row = $result_VC->fetch_assoc()){
			$sum=$sum+strtotime($row["min(wifidata.times)"])-strtotime($row["ltc.times"]);
			$i=$i+1;
			}
		}
	//平均时间
	$avg=intval($sum/$i);
	$days = intval($avg/86400);
	$remain = $avg%86400;
	$hours = intval($remain/3600);
	$remain = $remain%3600;
    $mins = intval($remain/60);
	
	$cycle=$days."天 ".$hours."小时 ".$mins."分钟";
?>